<template>
  <div>
    <van-nav-bar class="navhome" left-text="返回" left-arrow>
      <template #left>
        <img :src="logopng" alt="" />
      </template>
      <template #right>
        <div class="searchbor" @click="tosearch">
          <van-icon name="search" size="22" />
        </div>
      </template>
    </van-nav-bar>
    <van-tabs v-model="active">
      <van-tab
        v-for="(item, index) in channelsarr"
        :key="index"
        :title="item.name"
      >
        <articleList :channelid="item.id"></articleList>
      </van-tab>
    </van-tabs>
  </div>
</template>
<script>
import logopng from '../../assets/logo.png'
import { getchannels } from '../../api/home'
import articleList from './articleList.vue'
// import axios from 'axios'
// import 变量名（一般写子组件名） from '其他子组件路径'
export default {
  components: {
    articleList
  },
  name: 'home',
  data () {
    return {
      // msg:''
      logopng,
      active: 0,
      channelsarr: []
    }
  },
  created () {
    getchannels().then(res => {
      console.log(res)
      this.channelsarr = res.data.data.channels
    })
  },
  methods: {
    tosearch () {
      this.$router.push({ path: '/search' })
    }
  }
}
</script>
<style lang="less">
.van-nav-bar.navhome {
  background-color: black;
  img {
    height: 100%;
  }
  .searchbor {
    float: right;
    width: 100px;
    height: 30px;
    border: 1px solid #272822;
    border-radius: 8px;
    padding-right: 5px;
    background-color: #363636;
    .van-icon-search {
      float: right;
      color: #fff;
    }
  }
}
</style>
